package org.example.test_4_20;

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.Set;

public class Main {

    public static void main(String[] args) {
        //添加浏览器配置
        ChromeOptions options = new ChromeOptions();
        //1)允许任何来源的远程连接
        options.addArguments("--remote-allow-origins=*");
        //创建浏览器驱动对象
        ChromeDriver driver = new ChromeDriver(options);
        //访问百度⽹⻚
        driver.get("https://www.baidu.com");
        test1(driver);
    }
    public static void test1(ChromeDriver driver) {
        //搜索“遇事问春风乄”
        driver.findElement(By.cssSelector("#kw")).sendKeys("遇事问春风乄");
        //找到百度一下并点击
        driver.findElement(By.cssSelector("#su")).click();
        String curWindow = driver.getWindowHandle();
        Set<String> allWindow = driver.getWindowHandles();
        for( String w : allWindow){
            if(w!=curWindow){
                driver.switchTo().window(w);
            }
        }
    }
}
